<?php
include('includes/connexion.php');
$adminmanager = new AdminManager($connexion);
$elevemanager = new EleveManager($connexion);
session_start();
include('includes/secu.php');

$resultatmanager = new ResultatManager($connexion);
$testmanager = new TestManager($connexion);
$reponsemanager = new ReponseManager($connexion);
$exercicemanager = new ExerciceManager($connexion);
$questionmanager = new QuestionManager($connexion);

$idEleve = $resultatmanager->get($_GET['id'])->idRefEleve();
$idTest = $resultatmanager->get($_GET['id'])->idRefTest();
?>
<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
  <title><?php echo "Rapport de résultat de ".$elevemanager->get($idEleve)->prenom()." ".$elevemanager->get($idEleve)->nom()." du ".date("d/m/Y"); ?></title>

  <meta charset="utf-8">
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width">

  <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,700italic,400,600,700">
  <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Oswald:400,300,700">
  <link rel="stylesheet" href="css/font-awesome.min.css">
  <link rel="stylesheet" href="js/libs/css/ui-lightness/jquery-ui-1.9.2.custom.min.css">
  <link rel="stylesheet" href="css/bootstrap.min.css">

    <!-- App CSS -->
  <link rel="stylesheet" href="css/target-admin.css">
  <link rel="stylesheet" href="css/custom.css">


  <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
  <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
  <![endif]-->
</head>

<body>

<div class="container">

  <div class="content">

    <div class="content-container">
	<br><br>
      
      <div class="row">
        <div style="float:left;">
        <?php echo "Le ".date("d/m/Y")."<br>Prénom : ".$elevemanager->get($idEleve)->prenom()."<br>Nom : ".$elevemanager->get($idEleve)->nom()."<br>Date de naissance : ".date("d/m/Y", $elevemanager->get($idEleve)->datenaissance())."<br>Test : ".$testmanager->get($idTest)->intitule(); ?>
        </div>
        
        <div align="right">14, rue Romarin<br>69001 LYON<br>Tél : 04 78 28 07 01<br>Fax : 04 78 30 17 22<br>accueil@centreorientationscolaire.fr<br></div>     
      </div>
      
		<hr><div class="content-header-title" align="center">Centre d'Orientation Scolaire</div><hr>

<?php 	$type = array();
		foreach($resultatmanager->ListExercice($idEleve, $idTest) as $ex)
		{
			$exo = $exercicemanager->get($ex);
			if($exo->idRefExemple() == 0)
			{
				$type[] = $exo->type();
				echo "<h4>".$exo->intitule()."</h4>"; ?>        
              <table 
                class="table table-striped table-bordered table-hover table-highlight table-checkable" 
                data-provide="datatable" 
                data-display-rows="10"
                data-info="false"
                data-search="false"
                data-length-change="true"
                data-paginate="false"
              >
                  <tbody>
                  <tr>
                  <td id="legend-<?php echo $ex; ?>"></td>
                  <td><div id="stacked-horizontal-chart-<?php echo $ex; ?>" class="chart-holder" style="height:100px;"></div></td>
                  </tr>
                  </tbody>
                </table>
<?php } } 
$verbal = false;
$logique = false;
$numerique = false;
$spatial = false;
foreach($type as $typ)
{
	if($typ == 'R' || $typ == 'A' || $typ == 'TT')
		$verbal = true;
	if($typ == 'D')
		$logique = true;
	if($typ == 'SN')
		$numerique = true;
	if($typ == 'BB')
		$spatial = true;
}

if($verbal){ ?>
				<h4>Aptitudes verbales, maitrise de la langue</h4>        
              <table 
                class="table table-striped table-bordered table-hover table-highlight table-checkable" 
                data-provide="datatable" 
                data-display-rows="10"
                data-info="false"
                data-search="false"
                data-length-change="true"
                data-paginate="false"
              >
                  <tbody>
                  <tr>
                  <td id="legend-verbal"></td>
                  <td><div id="stacked-horizontal-chart-verbal" class="chart-holder" style="height:100px;"></div></td>
                  </tr>
                  </tbody>
                </table>		
<?php }
if($logique){ ?>
				<h4>Aptitude au raisonnement abstrait</h4>        
              <table 
                class="table table-striped table-bordered table-hover table-highlight table-checkable" 
                data-provide="datatable" 
                data-display-rows="10"
                data-info="false"
                data-search="false"
                data-length-change="true"
                data-paginate="false"
              >
                  <tbody>
                  <tr>
                  <td id="legend-logique"></td>
                  <td><div id="stacked-horizontal-chart-logique" class="chart-holder" style="height:100px;"></div></td>
                  </tr>
                  </tbody>
                </table>		
<?php }
if($numerique){ ?>
				<h4>Aptitude au raisonnement numérique</h4>        
              <table 
                class="table table-striped table-bordered table-hover table-highlight table-checkable" 
                data-provide="datatable" 
                data-display-rows="10"
                data-info="false"
                data-search="false"
                data-length-change="true"
                data-paginate="false"
              >
                  <tbody>
                  <tr>
                  <td id="legend-numerique"></td>
                  <td><div id="stacked-horizontal-chart-numerique" class="chart-holder" style="height:100px;"></div></td>
                  </tr>
                  </tbody>
                </table>		
<?php }
if($spatial){ ?>
				<h4>Aptitude au raisonnement logique concret</h4>        
              <table 
                class="table table-striped table-bordered table-hover table-highlight table-checkable" 
                data-provide="datatable" 
                data-display-rows="10"
                data-info="false"
                data-search="false"
                data-length-change="true"
                data-paginate="false"
              >
                  <tbody>
                  <tr>
                  <td id="legend-spatial"></td>
                  <td><div id="stacked-horizontal-chart-spatial" class="chart-holder" style="height:100px;"></div></td>
                  </tr>
                  </tbody>
                </table>		
<?php } ?>
   
        <br><br><table class="table table-striped table-bordered table-hover table-highlight table-checkable"><thead><tr><td style="color:white;">Commentaire</td></tr></thead><tbody><tr><td><textarea style="width:100%;height:100px;"></textarea></td></tr></tbody></table> 
		
        
        <p>
        <strong>VERBAL</strong><br/>
        Les aptitudes de votre enfant à exercer sa pensée sur un support verbal : maîtrise du vocabulaire - aptitude à raisonner (sérier, classer, comparer, généraliser), compréhension et jugement.<br/>
        <strong>LOGIQUE ABSTRAITE</strong><br/>
        Les aptitudes de votre enfant à raisonner sur un support abstrait (formuler des hypothèses et les vérifier)<br/>
        <strong>NUMERIQUE</strong><br/>
        Ce test révèle des habiletés à utiliser des nombres et à raisonner du particulier au général,à trouver des règles d'ensemble.<br/>
        <strong>SPATIAL</strong><br/>
        Les aptitudes de votre enfant à se représenter des objets en 2 ou 3 dimensions dans l'espace et à raisonner sur un support concret. <br/>       
        </p>

    </div> <!-- /.content-container -->
      
  </div> <!-- /.content -->

</div> <!-- /.container -->

  <script src="js/libs/jquery-1.10.1.min.js"></script>
  <script src="js/libs/jquery-ui-1.9.2.custom.min.js"></script>
  <script src="js/libs/bootstrap.min.js"></script>

  <!--[if lt IE 9]>
  <script src="./js/libs/excanvas.compiled.js"></script>
  <![endif]-->
  
  <!-- Plugin JS -->
  <script src="js/plugins/flot/jquery.flot.js"></script>
  <script src="js/plugins/flot/jquery.flot.orderBars.js"></script>
  <script src="js/plugins/flot/jquery.flot.pie.js"></script>
  <script src="js/plugins/flot/jquery.flot.stack.js"></script>
  <script src="js/plugins/flot/jquery.flot.tooltip.min.js"></script>
  <script src="js/plugins/flot/jquery.flot.resize.js"></script>

  <!-- App JS -->
  <script src="js/target-admin.js"></script>
<?php 	foreach($resultatmanager->ListExercice($idEleve, $idTest) as $ex)
		{
			$exo = $exercicemanager->get($ex);
			if($exo->idRefExemple() == 0)
			{ ?>  
  <!-- Plugin JS -->
  <script type="text/javascript">
	$(function () {
	
		var ds=[], data, chartOptions;		
<?php
	$reponseJuste = 0;
	foreach($resultatmanager->getByExerciceEleveTest($ex,$idEleve,$idTest) as $res)
	{
		if($reponsemanager->get($res->idRefReponse())->correcte() == 1){
			$reponseJuste++;
		}
	}
	
	$rapidite = $resultatmanager->getByExerciceEleveTest($ex,$idEleve,$idTest)[0]->temps() / $exo->duree_seconde();
	$rapidite *= 100;
	
	$txRapidite = 0;
	foreach($resultatmanager->getByExercice($ex) as $res)
	{
		$txRapidite += $res->temps();
	}
	$txRapidite /= sizeof($resultatmanager->getByExercice($ex));
	$txRapidite /= $exo->duree_seconde();
	$txRapidite *= 100;
	
	$reponseRepondu = sizeof($resultatmanager->getQuestion($ex, $idEleve));

	
	$moyenneRep = number_format($resultatmanager->TxReponseCorrecte($ex),2);
	if($moyenneRep < 50)
	{
		$ecartfortRep = ($moyenneRep * 2) - ($moyenneRep*0.1);
		$ecartfaibleRep = $moyenneRep / 2;
		$ecartmidRep = 100-$ecartfortRep-$ecartfortRep-$moyenneRep;	
	} else {
		$ecartfaibleRep = ($moyenneRep / 2) - ($moyenneRep*0.1);
		$ecartfortRep = (100 - $moyenneRep) / 2;	
		$ecartmidRep = $moyenneRep-$ecartfaibleRep-$ecartfaibleRep;	
	}

	$moyenneRap = number_format($txRapidite,2);;
	if($moyenneRap < 50)
	{
		$ecartfortRap = ($moyenneRap * 2) - ($moyenneRap*0.1);
		$ecartfaibleRap = $moyenneRap / 2;
		$ecartmidRap = 100-$ecartfortRap-$ecartfortRap-$moyenneRap;	
	} else {
		$ecartfaibleRap = ($moyenneRap / 2) - ($moyenneRap*0.1);
		$ecartfortRap = (100 - $moyenneRap) / 2;	
		$ecartmidRap = $moyenneRap-$ecartfaibleRap-$ecartfaibleRap;	
	}
?>		
		ds.push ([[<?php echo $ecartfaibleRap; ?>, 1.5], [<?php echo $ecartfaibleRep; ?>, 3]]);
		ds.push ([[<?php echo $ecartfaibleRap; ?>, 1.5], [<?php echo $ecartfaibleRep; ?>, 3]]);
		ds.push ([[<?php echo $ecartmidRap; ?>, 1.5], [<?php echo $ecartmidRep; ?>, 3]]);
		ds.push ([[<?php echo $ecartfortRap; ?>, 1.5], [<?php echo $ecartfortRep; ?>, 3]]);
		ds.push ([[<?php echo $ecartfortRap; ?>, 1.5], [<?php echo $ecartfortRep; ?>, 3]]);
		ds.push ([[<?php echo number_format(($reponseRepondu/$exercicemanager->getNbQuestion($ex))*100,2); ?>, 0], [<?php echo number_format($rapidite,2); ?>, 1], [<?php echo number_format(($reponseJuste/$exercicemanager->getNbReponseJuste($ex))*100,2); ?>, 2.5]]);
	
		data = [ {
			label: 'Faible',
			data: ds[0],
			color: 'red'
		}, {
			label: 'Moyen',
			data: ds[1],
			color: 'orange'
		}, {
			label: 'Assez bien',
			data: ds[2],
			color: 'blue'
		}, {
			label: 'Bien',
			data: ds[3],
			color: 'green'
		}, {
			label: 'Très bien',
			data: ds[4],
			color: 'yellow'
		}, {
			label: 'Résultat',
			data: ds[5],
			color: 'black'
		}];
	
		chartOptions = {
			xaxis: {
				ticks: [<?php for($i = 0; $i <= 100; $i=$i+5){ echo "[".$i.", '".$i."%'],"; } ?>]
			},
			yaxis: {
				ticks: [[0, "Question traitée"], [1.5, "Temps restant"], [3, "Réponse juste"]]
			},
			grid: {
				hoverable: true,
				clickable: false,
				borderWidth: 0
			},
			legend: {
				//position: "sw",
				container: "#legend-<?php echo $ex; ?>"
  			},
			series: {
				stack: true
			},
			bars: {
				horizontal: true,
				show: true,
				barWidth: .25,
				fill: true,
				lineWidth: 0,
				fillColor: { colors: [ { opacity: 1 }, { opacity: 1 } ] }
			},
			
			tooltip: true,
	
			tooltipOpts: {
				content: '%s: %x'
			},
			colors: target_admin.layoutColors
		}
	
	
		
		var holder = $('#stacked-horizontal-chart-<?php echo $ex; ?>');
	
		if (holder.length) {
			$.plot(holder, data, chartOptions );
		}
	
	
	
	
	});
  </script>
<?php } } ?>

<?php 	if($verbal){?>  
  <!-- Plugin JS -->
  <script type="text/javascript">
	$(function () {
	
		var ds=[], data, chartOptions;		
<?php
	$lstAllExercice = $resultatmanager->ListExercice($idEleve, $idTest);
	$lstExercice = array();
	foreach($lstAllExercice as $lst)
	{
		if($exercicemanager->get($lst)->idRefExemple() == 0)
		{
			if($exercicemanager->get($lst)->type() == 'R' || $exercicemanager->get($lst)->type() == 'A' || $exercicemanager->get($lst)->type() == 'TT')
			{
				$lstExercice[] = $lst;
			}
		}
	}
	
	/*Réponse juste*/
	$reponseJuste = 0;
	foreach($lstExercice as $ex)
	{
		foreach($resultatmanager->getByExerciceEleveTest($ex,$idEleve,$idTest) as $res)
		{
			if($reponsemanager->get($res->idRefReponse())->correcte() == 1){
				$reponseJuste++;
			}
			$reponseJuste /= $exercicemanager->getNbReponseJuste($ex);
		}
	}
	$reponseJuste *= 100;
	$reponseJuste *= sizeof($lstExercice);
	$reponseJuste = number_format($reponseJuste,2);
	/***************/
	
	/*Rapidité*/
	$rapidite = 0;
	foreach($lstExercice as $ex)
	{
		$rapidite += $resultatmanager->getByExerciceEleveTest($ex,$idEleve,$idTest)[0]->temps() / $exercicemanager->get($ex)->duree_seconde();
	}
	$rapidite *= 100;
	$rapidite /= sizeof($lstExercice);
	$rapidite = number_format($rapidite,2);
	/**********/
	
	/*Taux Rapidité*/
	$txRapidite = 0;
	$nbResultRapidite = 0;
	$duree_seconde_rapidite = 0;
	foreach($lstExercice as $ex)
	{
		foreach($resultatmanager->getByExercice($ex) as $res)
		{
			$txRapidite += $res->temps();
		}
		$nbResultRapidite += sizeof($resultatmanager->getByExercice($ex));
		$duree_seconde_rapidite += $exercicemanager->get($ex)->duree_seconde();
	}
	$txRapidite /= $nbResultRapidite;
	$txRapidite /= $duree_seconde_rapidite;
	$txRapidite *= 100;
	/****************/
	
	/*Réponse traité*/
	$reponseRepondu = 0;
	foreach($lstExercice as $ex)
	{
		$reponseRepondu += sizeof($resultatmanager->getQuestion($ex, $idEleve));
		$reponseRepondu /= $exercicemanager->getNbQuestion($ex);
	}
	$reponseRepondu /= sizeof($lstExercice);
	$reponseRepondu *= 100;
	$reponseRepondu = number_format($reponseRepondu,2);
	/****************/
	
	/*Etalonnage*/
	$moyenneRep = 0;
	foreach($lstExercice as $ex)
	{
		$moyenneRep += number_format($resultatmanager->TxReponseCorrecte($ex),2);
	}
	
	if($moyenneRep < 50)
	{
		$ecartfortRep = ($moyenneRep * 2) - ($moyenneRep*0.1);
		$ecartfaibleRep = $moyenneRep / 2;
		$ecartmidRep = 100-$ecartfortRep-$ecartfortRep-$moyenneRep;	
	} else {
		$ecartfaibleRep = ($moyenneRep / 2) - ($moyenneRep*0.1);
		$ecartfortRep = (100 - $moyenneRep) / 2;	
		$ecartmidRep = $moyenneRep-$ecartfaibleRep-$ecartfaibleRep;	
	}

	$moyenneRap = number_format($txRapidite,2);
	if($moyenneRap < 50)
	{
		$ecartfortRap = ($moyenneRap * 2) - ($moyenneRap*0.1);
		$ecartfaibleRap = $moyenneRap / 2;
		$ecartmidRap = 100-$ecartfortRap-$ecartfortRap-$moyenneRap;	
	} else {
		$ecartfaibleRap = ($moyenneRap / 2) - ($moyenneRap*0.1);
		$ecartfortRap = (100 - $moyenneRap) / 2;	
		$ecartmidRap = $moyenneRap-$ecartfaibleRap-$ecartfaibleRap;	
	}
	/************/
?>		
		ds.push ([[<?php echo $ecartfaibleRap; ?>, 1.5], [<?php echo $ecartfaibleRep; ?>, 3]]);
		ds.push ([[<?php echo $ecartfaibleRap; ?>, 1.5], [<?php echo $ecartfaibleRep; ?>, 3]]);
		ds.push ([[<?php echo $ecartmidRap; ?>, 1.5], [<?php echo $ecartmidRep; ?>, 3]]);
		ds.push ([[<?php echo $ecartfortRap; ?>, 1.5], [<?php echo $ecartfortRep; ?>, 3]]);
		ds.push ([[<?php echo $ecartfortRap; ?>, 1.5], [<?php echo $ecartfortRep; ?>, 3]]);
		ds.push ([[<?php echo $reponseRepondu; ?>, 0], [<?php echo $rapidite; ?>, 1], [<?php echo $reponseJuste; ?>, 2.5]]);
	
		data = [ {
			label: 'Faible',
			data: ds[0],
			color: 'red'
		}, {
			label: 'Moyen',
			data: ds[1],
			color: 'orange'
		}, {
			label: 'Assez bien',
			data: ds[2],
			color: 'blue'
		}, {
			label: 'Bien',
			data: ds[3],
			color: 'green'
		}, {
			label: 'Très bien',
			data: ds[4],
			color: 'yellow'
		}, {
			label: 'Résultat',
			data: ds[5],
			color: 'black'
		}];
	
		chartOptions = {
			xaxis: {
				ticks: [<?php for($i = 0; $i <= 100; $i=$i+5){ echo "[".$i.", '".$i."%'],"; } ?>]
			},
			yaxis: {
				ticks: [[0, "Question traitée"], [1.5, "Temps restant"], [3, "Réponse juste"]]
			},
			grid: {
				hoverable: true,
				clickable: false,
				borderWidth: 0
			},
			legend: {
				//position: "sw",
				container: "#legend-verbal"
  			},
			series: {
				stack: true
			},
			bars: {
				horizontal: true,
				show: true,
				barWidth: .25,
				fill: true,
				lineWidth: 0,
				fillColor: { colors: [ { opacity: 1 }, { opacity: 1 } ] }
			},
			
			tooltip: true,
	
			tooltipOpts: {
				content: '%s: %x'
			},
			colors: target_admin.layoutColors
		}
	
	
		
		var holder = $('#stacked-horizontal-chart-verbal');
	
		if (holder.length) {
			$.plot(holder, data, chartOptions );
		}
	
	
	
	
	});
  </script>
<?php } ?>

<?php 	if($logique){?>  
  <!-- Plugin JS -->
  <script type="text/javascript">
	$(function () {
	
		var ds=[], data, chartOptions;		
<?php
	$lstAllExercice = $resultatmanager->ListExercice($idEleve, $idTest);
	$lstExercice = array();
	foreach($lstAllExercice as $lst)
	{
		if($exercicemanager->get($lst)->idRefExemple() == 0)
		{
			if($exercicemanager->get($lst)->type() == 'D')
			{
				$lstExercice[] = $lst;
			}
		}
	}
	
	/*Réponse juste*/
	$reponseJuste = 0;
	foreach($lstExercice as $ex)
	{
		foreach($resultatmanager->getByExerciceEleveTest($ex,$idEleve,$idTest) as $res)
		{
			if($reponsemanager->get($res->idRefReponse())->correcte() == 1){
				$reponseJuste++;
			}
			$reponseJuste /= $exercicemanager->getNbReponseJuste($ex);
		}
	}
	$reponseJuste *= 100;
	$reponseJuste *= sizeof($lstExercice);
	$reponseJuste = number_format($reponseJuste,2);
	/***************/
	
	/*Rapidité*/
	$rapidite = 0;
	foreach($lstExercice as $ex)
	{
		$rapidite += $resultatmanager->getByExerciceEleveTest($ex,$idEleve,$idTest)[0]->temps() / $exercicemanager->get($ex)->duree_seconde();
	}
	$rapidite *= 100;
	$rapidite /= sizeof($lstExercice);
	$rapidite = number_format($rapidite,2);
	/**********/
	
	/*Taux Rapidité*/
	$txRapidite = 0;
	$nbResultRapidite = 0;
	$duree_seconde_rapidite = 0;
	foreach($lstExercice as $ex)
	{
		foreach($resultatmanager->getByExercice($ex) as $res)
		{
			$txRapidite += $res->temps();
		}
		$nbResultRapidite += sizeof($resultatmanager->getByExercice($ex));
		$duree_seconde_rapidite += $exercicemanager->get($ex)->duree_seconde();
	}
	$txRapidite /= $nbResultRapidite;
	$txRapidite /= $duree_seconde_rapidite;
	$txRapidite *= 100;
	/****************/
	
	/*Réponse traité*/
	$reponseRepondu = 0;
	foreach($lstExercice as $ex)
	{
		$reponseRepondu += sizeof($resultatmanager->getQuestion($ex, $idEleve));
		$reponseRepondu /= $exercicemanager->getNbQuestion($ex);
	}
	$reponseRepondu /= sizeof($lstExercice);
	$reponseRepondu *= 100;
	$reponseRepondu = number_format($reponseRepondu,2);
	/****************/
	
	/*Etalonnage*/
	$moyenneRep = 0;
	foreach($lstExercice as $ex)
	{
		$moyenneRep += number_format($resultatmanager->TxReponseCorrecte($ex),2);
	}
	
	if($moyenneRep < 50)
	{
		$ecartfortRep = ($moyenneRep * 2) - ($moyenneRep*0.1);
		$ecartfaibleRep = $moyenneRep / 2;
		$ecartmidRep = 100-$ecartfortRep-$ecartfortRep-$moyenneRep;	
	} else {
		$ecartfaibleRep = ($moyenneRep / 2) - ($moyenneRep*0.1);
		$ecartfortRep = (100 - $moyenneRep) / 2;	
		$ecartmidRep = $moyenneRep-$ecartfaibleRep-$ecartfaibleRep;	
	}

	$moyenneRap = number_format($txRapidite,2);
	if($moyenneRap < 50)
	{
		$ecartfortRap = ($moyenneRap * 2) - ($moyenneRap*0.1);
		$ecartfaibleRap = $moyenneRap / 2;
		$ecartmidRap = 100-$ecartfortRap-$ecartfortRap-$moyenneRap;	
	} else {
		$ecartfaibleRap = ($moyenneRap / 2) - ($moyenneRap*0.1);
		$ecartfortRap = (100 - $moyenneRap) / 2;	
		$ecartmidRap = $moyenneRap-$ecartfaibleRap-$ecartfaibleRap;	
	}
	/************/
?>		
		ds.push ([[<?php echo $ecartfaibleRap; ?>, 1.5], [<?php echo $ecartfaibleRep; ?>, 3]]);
		ds.push ([[<?php echo $ecartfaibleRap; ?>, 1.5], [<?php echo $ecartfaibleRep; ?>, 3]]);
		ds.push ([[<?php echo $ecartmidRap; ?>, 1.5], [<?php echo $ecartmidRep; ?>, 3]]);
		ds.push ([[<?php echo $ecartfortRap; ?>, 1.5], [<?php echo $ecartfortRep; ?>, 3]]);
		ds.push ([[<?php echo $ecartfortRap; ?>, 1.5], [<?php echo $ecartfortRep; ?>, 3]]);
		ds.push ([[<?php echo $reponseRepondu; ?>, 0], [<?php echo $rapidite; ?>, 1], [<?php echo $reponseJuste; ?>, 2.5]]);
	
		data = [ {
			label: 'Faible',
			data: ds[0],
			color: 'red'
		}, {
			label: 'Moyen',
			data: ds[1],
			color: 'orange'
		}, {
			label: 'Assez bien',
			data: ds[2],
			color: 'blue'
		}, {
			label: 'Bien',
			data: ds[3],
			color: 'green'
		}, {
			label: 'Très bien',
			data: ds[4],
			color: 'yellow'
		}, {
			label: 'Résultat',
			data: ds[5],
			color: 'black'
		}];
	
		chartOptions = {
			xaxis: {
				ticks: [<?php for($i = 0; $i <= 100; $i=$i+5){ echo "[".$i.", '".$i."%'],"; } ?>]
			},
			yaxis: {
				ticks: [[0, "Question traitée"], [1.5, "Temps restant"], [3, "Réponse juste"]]
			},
			grid: {
				hoverable: true,
				clickable: false,
				borderWidth: 0
			},
			legend: {
				//position: "sw",
				container: "#legend-logique"
  			},
			series: {
				stack: true
			},
			bars: {
				horizontal: true,
				show: true,
				barWidth: .25,
				fill: true,
				lineWidth: 0,
				fillColor: { colors: [ { opacity: 1 }, { opacity: 1 } ] }
			},
			
			tooltip: true,
	
			tooltipOpts: {
				content: '%s: %x'
			},
			colors: target_admin.layoutColors
		}
	
	
		
		var holder = $('#stacked-horizontal-chart-logique');
	
		if (holder.length) {
			$.plot(holder, data, chartOptions );
		}
	
	
	
	
	});
  </script>
<?php } ?>

<?php 	if($numerique){?>  
  <!-- Plugin JS -->
  <script type="text/javascript">
	$(function () {
	
		var ds=[], data, chartOptions;		
<?php
	$lstAllExercice = $resultatmanager->ListExercice($idEleve, $idTest);
	$lstExercice = array();
	foreach($lstAllExercice as $lst)
	{
		if($exercicemanager->get($lst)->idRefExemple() == 0)
		{
			if($exercicemanager->get($lst)->type() == 'SN')
			{
				$lstExercice[] = $lst;
			}
		}
	}
	
	/*Réponse juste*/
	$reponseJuste = 0;
	foreach($lstExercice as $ex)
	{
		foreach($resultatmanager->getByExerciceEleveTest($ex,$idEleve,$idTest) as $res)
		{
			if($reponsemanager->get($res->idRefReponse())->correcte() == 1){
				$reponseJuste++;
			}
			$reponseJuste /= $exercicemanager->getNbReponseJuste($ex);
		}
	}
	$reponseJuste *= 100;
	$reponseJuste *= sizeof($lstExercice);
	$reponseJuste = number_format($reponseJuste,2);
	/***************/
	
	/*Rapidité*/
	$rapidite = 0;
	foreach($lstExercice as $ex)
	{
		$rapidite += $resultatmanager->getByExerciceEleveTest($ex,$idEleve,$idTest)[0]->temps() / $exercicemanager->get($ex)->duree_seconde();
	}
	$rapidite *= 100;
	$rapidite /= sizeof($lstExercice);
	$rapidite = number_format($rapidite,2);
	/**********/
	
	/*Taux Rapidité*/
	$txRapidite = 0;
	$nbResultRapidite = 0;
	$duree_seconde_rapidite = 0;
	foreach($lstExercice as $ex)
	{
		foreach($resultatmanager->getByExercice($ex) as $res)
		{
			$txRapidite += $res->temps();
		}
		$nbResultRapidite += sizeof($resultatmanager->getByExercice($ex));
		$duree_seconde_rapidite += $exercicemanager->get($ex)->duree_seconde();
	}
	$txRapidite /= $nbResultRapidite;
	$txRapidite /= $duree_seconde_rapidite;
	$txRapidite *= 100;
	/****************/
	
	/*Réponse traité*/
	$reponseRepondu = 0;
	foreach($lstExercice as $ex)
	{
		$reponseRepondu += sizeof($resultatmanager->getQuestion($ex, $idEleve));
		$reponseRepondu /= $exercicemanager->getNbQuestion($ex);
	}
	$reponseRepondu /= sizeof($lstExercice);
	$reponseRepondu *= 100;
	$reponseRepondu = number_format($reponseRepondu,2);
	/****************/
	
	/*Etalonnage*/
	$moyenneRep = 0;
	foreach($lstExercice as $ex)
	{
		$moyenneRep += number_format($resultatmanager->TxReponseCorrecte($ex),2);
	}
	
	if($moyenneRep < 50)
	{
		$ecartfortRep = ($moyenneRep * 2) - ($moyenneRep*0.1);
		$ecartfaibleRep = $moyenneRep / 2;
		$ecartmidRep = 100-$ecartfortRep-$ecartfortRep-$moyenneRep;	
	} else {
		$ecartfaibleRep = ($moyenneRep / 2) - ($moyenneRep*0.1);
		$ecartfortRep = (100 - $moyenneRep) / 2;	
		$ecartmidRep = $moyenneRep-$ecartfaibleRep-$ecartfaibleRep;	
	}

	$moyenneRap = number_format($txRapidite,2);
	if($moyenneRap < 50)
	{
		$ecartfortRap = ($moyenneRap * 2) - ($moyenneRap*0.1);
		$ecartfaibleRap = $moyenneRap / 2;
		$ecartmidRap = 100-$ecartfortRap-$ecartfortRap-$moyenneRap;	
	} else {
		$ecartfaibleRap = ($moyenneRap / 2) - ($moyenneRap*0.1);
		$ecartfortRap = (100 - $moyenneRap) / 2;	
		$ecartmidRap = $moyenneRap-$ecartfaibleRap-$ecartfaibleRap;	
	}
	/************/
?>		
		ds.push ([[<?php echo $ecartfaibleRap; ?>, 1.5], [<?php echo $ecartfaibleRep; ?>, 3]]);
		ds.push ([[<?php echo $ecartfaibleRap; ?>, 1.5], [<?php echo $ecartfaibleRep; ?>, 3]]);
		ds.push ([[<?php echo $ecartmidRap; ?>, 1.5], [<?php echo $ecartmidRep; ?>, 3]]);
		ds.push ([[<?php echo $ecartfortRap; ?>, 1.5], [<?php echo $ecartfortRep; ?>, 3]]);
		ds.push ([[<?php echo $ecartfortRap; ?>, 1.5], [<?php echo $ecartfortRep; ?>, 3]]);
		ds.push ([[<?php echo $reponseRepondu; ?>, 0], [<?php echo $rapidite; ?>, 1], [<?php echo $reponseJuste; ?>, 2.5]]);
	
		data = [ {
			label: 'Faible',
			data: ds[0],
			color: 'red'
		}, {
			label: 'Moyen',
			data: ds[1],
			color: 'orange'
		}, {
			label: 'Assez bien',
			data: ds[2],
			color: 'blue'
		}, {
			label: 'Bien',
			data: ds[3],
			color: 'green'
		}, {
			label: 'Très bien',
			data: ds[4],
			color: 'yellow'
		}, {
			label: 'Résultat',
			data: ds[5],
			color: 'black'
		}];
	
		chartOptions = {
			xaxis: {
				ticks: [<?php for($i = 0; $i <= 100; $i=$i+5){ echo "[".$i.", '".$i."%'],"; } ?>]
			},
			yaxis: {
				ticks: [[0, "Question traitée"], [1.5, "Temps restant"], [3, "Réponse juste"]]
			},
			grid: {
				hoverable: true,
				clickable: false,
				borderWidth: 0
			},
			legend: {
				//position: "sw",
				container: "#legend-numerique"
  			},
			series: {
				stack: true
			},
			bars: {
				horizontal: true,
				show: true,
				barWidth: .25,
				fill: true,
				lineWidth: 0,
				fillColor: { colors: [ { opacity: 1 }, { opacity: 1 } ] }
			},
			
			tooltip: true,
	
			tooltipOpts: {
				content: '%s: %x'
			},
			colors: target_admin.layoutColors
		}
	
	
		
		var holder = $('#stacked-horizontal-chart-numerique');
	
		if (holder.length) {
			$.plot(holder, data, chartOptions );
		}
	
	
	
	
	});
  </script>
<?php } ?>

<?php 	if($spatial){?>  
  <!-- Plugin JS -->
  <script type="text/javascript">
	$(function () {
	
		var ds=[], data, chartOptions;		
<?php
	$lstAllExercice = $resultatmanager->ListExercice($idEleve, $idTest);
	$lstExercice = array();
	foreach($lstAllExercice as $lst)
	{
		if($exercicemanager->get($lst)->idRefExemple() == 0)
		{
			if($exercicemanager->get($lst)->type() == 'BB')
			{
				$lstExercice[] = $lst;
			}
		}
	}
	
	/*Réponse juste*/
	$reponseJuste = 0;
	foreach($lstExercice as $ex)
	{
		foreach($resultatmanager->getByExerciceEleveTest($ex,$idEleve,$idTest) as $res)
		{
			if($reponsemanager->get($res->idRefReponse())->correcte() == 1){
				$reponseJuste++;
			}
			$reponseJuste /= $exercicemanager->getNbReponseJuste($ex);
		}
	}
	$reponseJuste *= 100;
	$reponseJuste *= sizeof($lstExercice);
	$reponseJuste = number_format($reponseJuste,2);
	/***************/
	
	/*Rapidité*/
	$rapidite = 0;
	foreach($lstExercice as $ex)
	{
		$rapidite += $resultatmanager->getByExerciceEleveTest($ex,$idEleve,$idTest)[0]->temps() / $exercicemanager->get($ex)->duree_seconde();
	}
	$rapidite *= 100;
	$rapidite /= sizeof($lstExercice);
	$rapidite = number_format($rapidite,2);
	/**********/
	
	/*Taux Rapidité*/
	$txRapidite = 0;
	$nbResultRapidite = 0;
	$duree_seconde_rapidite = 0;
	foreach($lstExercice as $ex)
	{
		foreach($resultatmanager->getByExercice($ex) as $res)
		{
			$txRapidite += $res->temps();
		}
		$nbResultRapidite += sizeof($resultatmanager->getByExercice($ex));
		$duree_seconde_rapidite += $exercicemanager->get($ex)->duree_seconde();
	}
	$txRapidite /= $nbResultRapidite;
	$txRapidite /= $duree_seconde_rapidite;
	$txRapidite *= 100;
	/****************/
	
	/*Réponse traité*/
	$reponseRepondu = 0;
	foreach($lstExercice as $ex)
	{
		$reponseRepondu += sizeof($resultatmanager->getQuestion($ex, $idEleve));
		$reponseRepondu /= $exercicemanager->getNbQuestion($ex);
	}
	$reponseRepondu /= sizeof($lstExercice);
	$reponseRepondu *= 100;
	$reponseRepondu = number_format($reponseRepondu,2);
	/****************/
	
	/*Etalonnage*/
	$moyenneRep = 0;
	foreach($lstExercice as $ex)
	{
		$moyenneRep += number_format($resultatmanager->TxReponseCorrecte($ex),2);
	}
	
	if($moyenneRep < 50)
	{
		$ecartfortRep = ($moyenneRep * 2) - ($moyenneRep*0.1);
		$ecartfaibleRep = $moyenneRep / 2;
		$ecartmidRep = 100-$ecartfortRep-$ecartfortRep-$moyenneRep;	
	} else {
		$ecartfaibleRep = ($moyenneRep / 2) - ($moyenneRep*0.1);
		$ecartfortRep = (100 - $moyenneRep) / 2;	
		$ecartmidRep = $moyenneRep-$ecartfaibleRep-$ecartfaibleRep;	
	}

	$moyenneRap = number_format($txRapidite,2);
	if($moyenneRap < 50)
	{
		$ecartfortRap = ($moyenneRap * 2) - ($moyenneRap*0.1);
		$ecartfaibleRap = $moyenneRap / 2;
		$ecartmidRap = 100-$ecartfortRap-$ecartfortRap-$moyenneRap;	
	} else {
		$ecartfaibleRap = ($moyenneRap / 2) - ($moyenneRap*0.1);
		$ecartfortRap = (100 - $moyenneRap) / 2;	
		$ecartmidRap = $moyenneRap-$ecartfaibleRap-$ecartfaibleRap;	
	}
	/************/
?>		
		ds.push ([[<?php echo $ecartfaibleRap; ?>, 1.5], [<?php echo $ecartfaibleRep; ?>, 3]]);
		ds.push ([[<?php echo $ecartfaibleRap; ?>, 1.5], [<?php echo $ecartfaibleRep; ?>, 3]]);
		ds.push ([[<?php echo $ecartmidRap; ?>, 1.5], [<?php echo $ecartmidRep; ?>, 3]]);
		ds.push ([[<?php echo $ecartfortRap; ?>, 1.5], [<?php echo $ecartfortRep; ?>, 3]]);
		ds.push ([[<?php echo $ecartfortRap; ?>, 1.5], [<?php echo $ecartfortRep; ?>, 3]]);
		ds.push ([[<?php echo $reponseRepondu; ?>, 0], [<?php echo $rapidite; ?>, 1], [<?php echo $reponseJuste; ?>, 2.5]]);
	
		data = [ {
			label: 'Faible',
			data: ds[0],
			color: 'red'
		}, {
			label: 'Moyen',
			data: ds[1],
			color: 'orange'
		}, {
			label: 'Assez bien',
			data: ds[2],
			color: 'blue'
		}, {
			label: 'Bien',
			data: ds[3],
			color: 'green'
		}, {
			label: 'Très bien',
			data: ds[4],
			color: 'yellow'
		}, {
			label: 'Résultat',
			data: ds[5],
			color: 'black'
		}];
	
		chartOptions = {
			xaxis: {
				ticks: [<?php for($i = 0; $i <= 100; $i=$i+5){ echo "[".$i.", '".$i."%'],"; } ?>]
			},
			yaxis: {
				ticks: [[0, "Question traitée"], [1.5, "Temps restant"], [3, "Réponse juste"]]
			},
			grid: {
				hoverable: true,
				clickable: false,
				borderWidth: 0
			},
			legend: {
				//position: "sw",
				container: "#legend-spatial"
  			},
			series: {
				stack: true
			},
			bars: {
				horizontal: true,
				show: true,
				barWidth: .25,
				fill: true,
				lineWidth: 0,
				fillColor: { colors: [ { opacity: 1 }, { opacity: 1 } ] }
			},
			
			tooltip: true,
	
			tooltipOpts: {
				content: '%s: %x'
			},
			colors: target_admin.layoutColors
		}
	
	
		
		var holder = $('#stacked-horizontal-chart-spatial');
	
		if (holder.length) {
			$.plot(holder, data, chartOptions );
		}
	
	
	
	
	});
  </script>
<?php } ?>

</body>
</html>